<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sitemap extends CI_Controller {
  public function __construct() {
    parent::__construct();
  }

  public function index() {
    $this->load->helper('file');
    $this->load->library('parser');
    $this->load->model('sitemap/sitemap_model');
    $data['urls'] = $this->sitemap_model->generate_xml_sitemap();
    $data = $this->parser->parse('sitemap/sitemap_view', $data);
    try {
      write_file('application/cache/sitemap.xml', $data);
    } catch (Exception $e) {
      echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
  }
}